package com.webchat.chat.core.tools;

import com.webchat.chat.core.baseEntity.BasePersistenceEnum;

import java.util.Objects;

/**
 * Created by Owner on 2018/6/27.
 */
public class PersistenceEnumConverter {
    public static <E extends Enum<?> & BasePersistenceEnum> E codeOf(Class<E> enumClass, String code) {
        E[] enumConstants = enumClass.getEnumConstants();
        for (E e : enumConstants) {
            if (Objects.equals(e.getCode(), code))
                return e;
        }
        return null;
    }
}
